package com.wangshidai.util;

import java.sql.*;

public class DBHelper {
    //开门
    public static Connection getConn()  {
        try {
            //1. 搭桥
            Class.forName("com.mysql.cj.jdbc.Driver");
            //2. 开门
            Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/st0104?useSSL=false&serverTimezone=UTC", "root", "123456");
            return conn;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }
    //关门
    public static void close(PreparedStatement ps,Connection conn) throws Exception {
        ps.close();
        conn.close();
    }
    public static void close(ResultSet rs,PreparedStatement ps, Connection conn)  {
        try {
            rs.close();
            ps.close();
            conn.close();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }



}
